package dbops

import (
	"log"
)

// ReadVideoDeletionRecord 读取要删除的视频id
func ReadVideoDeletionRecord(count int) ([]string, error) {
	stmtOut, err := dbConn.Prepare("select video_if from video_del_rec limit 0,?")

	var ids []string

	if err != nil {
		return ids, err
	}

	rows, rowsErr := stmtOut.Query(count)
	if rowsErr != nil {
		return ids, err
	}

	for rows.Next() {
		var id string
		rowErr := rows.Scan(&id)
		if rowErr != nil {
			log.Printf("读取数据错误！%v", rowErr)
			return ids, err
		}

		ids = append(ids, id)
	}

	defer stmtOut.Close()
	return ids, nil
}

// DelVideoDeletionRecord 删除视频
func DelVideoDeletionRecord(vid string) error {
	stmDelete, err := dbConn.Prepare("delete from video_del_rec where id = ?")
	if err != nil {
		log.Printf("删除视频编译 SQL 出错：%v", err)
		return err
	}

	_, deleteErr := stmDelete.Exec(vid)
	if deleteErr != nil {
		return deleteErr
	}

	defer stmDelete.Close()
	return nil

}
